package wsp.dailymarket.deals.timed;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 * Run in the background checking the database for expired deals
 * @author Matt
 */
public class TimedDeals implements ServletContextListener {

	private ScheduledExecutorService scheduler;

	public void contextInitialized(ServletContextEvent sce) {
		scheduler = Executors.newSingleThreadScheduledExecutor();
		scheduler.scheduleAtFixedRate(new TimedDealsJob(), 0, 60, TimeUnit.SECONDS);
	}

	public void contextDestroyed(ServletContextEvent sce) {
		scheduler.shutdown();
	}

	public class TimedDealsJob implements Runnable {
		public void run() {
			//TODO Timed Deals
		}
	}
}
